package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.text.Html;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.framework.BasePresenter;
import com.taomu.app.zongchouhuli.http.res.ResLevenlEntity;
import com.taomu.app.zongchouhuli.moudle.mine.contract.UserMemberContract;
import com.taomu.app.zongchouhuli.moudle.mine.contract.impl.UserMemberPresenter;

public class UserMemberActivity extends BaseActivity<UserMemberContract.Presenter> implements UserMemberContract.View {

    private ImageView mBackIm;

    private TextView mRankTv;

    private TextView mUpGradeTv;

    private TextView mRechargeTv;

    private WebView mWebView;

    @Override
    protected void onDestroy() {
        mPresenter.onDetch();
        super.onDestroy();
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_member;
    }

    @Override
    protected void initView() {
        mBackIm = findViewById(R.id.member_back_im);
        mRankTv = findViewById(R.id.member_rank_tv);
        mUpGradeTv = findViewById(R.id.member_upgrade_tv);
        //mDesTv = findViewById(R.id.member_des_tv);
        mRechargeTv = findViewById(R.id.member_recharge_tv);
        mWebView = findViewById(R.id.web_view);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setTextSize(WebSettings.TextSize.NORMAL);
    }

    @Override
    protected void initData() {
       mPresenter.getLevenl();
       mPresenter.getArticleInfo();
    }

    @Override
    protected void initEvent() {
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mRechargeTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(UserRechargeActivity.class);
            }
        });
    }

    @Override
    protected UserMemberContract.Presenter createPresenter() {
        return new UserMemberPresenter(this);
    }

    @Override
    public void setLevenl(ResLevenlEntity entity) {
        mRankTv.setText(entity.getName());
        mUpGradeTv.setText("还差"+entity.getLeft()+"升级到"+entity.getNext_level());
    }

    @Override
    public void setArticleInfo(String html) {
        //mDesTv.setText(Html.fromHtml(html));
        mWebView.loadDataWithBaseURL (null, html, "text/html", "utf-8", null);
    }

    @Override
    public void setPresenter(UserMemberContract.Presenter presenter) {

    }
}
